<template>
	<view>
		<!-- 判断页面 -->
		<!-- 关注 -->
		<!-- 		<wanl-shop-find :windowHeight="windowHeight" v-if="title=='关注'" :headHeight="headHeight"
			:homeModules="common.modulesData.homeModules" :appConfig="common.appConfig" :user="user" /> -->
		<view class="" style="padding: 24rpx;">
			<goodslist :leftList='leftList' :rightList="rightList"></goodslist>
			<!-- <uni-load-more :status="status" :content-text="contentText" /> -->
		</view>
		<!-- 		<view class="" style="padding: 24rpx;" v-if="title=='推荐'">
			<goodslist :leftList='leftList' :rightList="rightList"></goodslist>
			<uni-load-more :status="status" :content-text="contentText" />
		</view>
		<view class="" v-if="title!='关注'&&title!='推荐'">
			<wanl-shop-category v-if="common.modulesData" :cid="Number(cid)" :headHeight="headHeight"
				:windowHeight="windowHeight" :homeModules="common.modulesData.homeModules"
				:childlist="common.modulesData.categoryModules[index].childlist" />
		</view>
		<home /> -->
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';
	import wanlShopPage from '@/components/wanl-shop/page';
	import wanlShopFind from '@/components/wanl-shop/find';
	import wanlShopCategory from '@/components/wanl-shop/category';
	import home from '@/components/home/index'
	export default {
		components: {
			wanlShopPage,
			wanlShopFind,
			wanlShopCategory,
			home
		},
		data() {
			return {
				headHeight: 0,
				windowHeight: 0,
				headTop: 0,
				index: 0,
				leftList: [],
				rightList: [],
				status: 'loading',
				contentText: {
					contentdown: '下拉加载更多',
					contentrefresh: '疯狂加载中...',
					contentnomore: this.$getText('我是有底线的')
				},
				current_page: 1, //当前页码
				last_page: 1, //总页码
				title: '',
				cid: null,
				dataList: []
			};
		},
		onLoad(o) {
			console.log(o.title)
			this.title = o.title
			if (this.title == '推荐') {
				this.loadData()
			} else {}
			this.index = o.index
			if (this.index) {
				this.cid = o.cid
			}
			// console.log(this.common.modulesData.categoryModules[this.index])

		},

		computed: {
			...mapState(['common', 'user', 'update'])
		},
		onShow() {
			// #ifdef APP-PLUS
			plus.navigator.setFullscreen(false);
			// #endif
			// 计算页面尺寸
			let sys = this.$wanlshop.wanlsys();
			this.headTop = sys.top;
			// this.headHeight = sys.height + uni.upx2px(60);
			this.windowHeight = sys.windowHeight;
			this.loadData()
		},
		methods: {
			async loadData(type) {
				this.status = 'loading';
				// 判断上拉还是下拉
				if (type === 'lower') {
					if (this.current_page >= this.last_page) {
						this.status = 'noMore';
						return false;
					} else {
						this.current_page += 1;
					}
				}
				await uni.request({
					url: '/wanlshop/product/new_follow',
					data: {
						page: this.current_page,
						pageSize: 9999
					},
					success: res => {
						if (type === 'lower') {
							this.dataList = this.dataList.concat(res.data.data);
						} else {
							this.dataList = res.data.data;
						}
						this.leftList = []
						this.rightList = []
						this.dataList.map((t, i) => {
							if (i % 2 == 0) {
								this.leftList.push(t)
							}
							if (i % 2 == 1) {
								this.rightList.push(t)
							}
						})
						this.current_page = res.data.current_page; //当前页码
						this.last_page = res.data.last_page; //总页码
						// 判断是否还有数据
						if (res.data.current_page === res.data.last_page || res.data.total === 0) {
							this.status = 'noMore';
						} else {
							this.status = 'more';
						}
						uni.stopPullDownRefresh()
					}
				});
			},
		}
	}
</script>

<style lang="less">

</style>